<?php
//
//	file: includes/ucp/ucp_advmsg_pm_box.php
//	begin: 10/07/2006
//	$Author: christopher $
//	$Revision: 28 $
//	$Date: 2008-01-28 23:55:41 +0000 (Mon, 28 Jan 2008) $
//	license: http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
//
//	description: this displays the various pm boxes available to a user and lists their contents

if ( !defined('IN_PHPBB') )
{
	die('Hack attempt');
}

include_once($config->url('includes/class_advmsg_pm'));

// sort and search options
$msgdays_list = array(0 => 'All_Posts', 1 => '1_Day', 7 => '7_Days', 14 => '2_Weeks', 30 => '1_Month', 90 => '3_Months', 180 => '6_Months', 364 =>'1_Year');
$available_sort = array(
	'subject' => 'Sort_Subject',
	'status' => 'Sort_Status',
	'user_from' => 'Sort_From',
	'posttime' => 'Sort_Posttime',
);
$sort_fields = array(
	'subject' => 'pm.privmsgs_subject',
	'status' => 'pm.privmsgs_type',
	'user_from' => 'pm.privmsgs_from_userid',
	'posttime' => 'pm.privmsgs_date',
);
$available_order = array(
	'' => 'Sort_Ascending',
	'desc' => 'Sort_Descending',
);
$order_fields = array(
	'' => '',
	'desc' => ' DESC',
);
$dft_sort = 'posttime';
$dft_order = 'desc';
$dft_folder = 'inbox';
$dft_save_folder = 'savebox';

$fields = array(
	'fromuser' => array('type' => 'pm_search_username', 'legend' => 'User_name', 'explain' => 'Search_wildcard_explain'),
	'msgdays' => array('type' => 'list', 'legend' => 'More_days_old', 'options' => $msgdays_list),
	'sort' => array('type' => 'list', 'legend' => 'Sort_by', 'options' => $available_sort, 'value' => $dft_sort),
	'order' => array('type' => 'list', 'combined' => true, 'options' => $available_order, 'value' => $dft_order),
);

class advnot_readbox extends form
{
	var $requester;
	var $parms;

	var $data;
	var $box_type;
	var $box_id;
	var $box;
	var $ppage;
	var $start;
	var $now;

	var $delete_box;
	var $privmsgs_ids;
	var $boxes;
	var $boxes_map;

	var $handler;

	function pm_box($requester, $parms='', &$fields)
	{
		global $config, $view_user, $dft_folder;

		$this->requester = $requester;
		$this->now = time();
		$this->parms = empty($parms) ? array() : $parms;
		$this->data = $this->boxes = $this->privmsg_ids = $this->boxes_map = $this->delete_box = $this->privmsgs_ids = array();
		$this->total = $this->ppage = $this->start = 0;

		// load box info
		$pm_boxes = new advnot_pm_boxes();
		$this->boxes = $pm_boxes->get_boxes($view_user->data['user_id']);
		$this->boxes_map = $pm_boxes->get_boxes_map($view_user->data['user_id']);
		unset($pm_boxes);
		if (_read('folder', TYPE_NO_HTML) != 'index')
		{
			$this->box = _read('folder', TYPE_NO_HTML, $dft_folder, $this->boxes_map);
			$this->box_id = $this->boxes_map[$this->box];
			$this->box_type = $this->boxes[$this->box_id]['pm_box_type'];
			// attachments
			if ( $config->data['mod_attachment_CH'] )
			{
				include($config->url('includes/class_thumbnail'));
				include($config->url('includes/class_attach_parent'));
				include($config->url('includes/class_attach_privmsg'));

				$attachment = new attach_privmsg();
				$attachment->action();
				$attachment->init($this->box);
			}
		}
		else
		{
			$this->box_id = 0;
			$this->box = 'PM_Home';
		}

		parent::form($fields);
	}

	function process()
	{
		if ( $this->init() )
		{
			$this->check();
			$this->validate();
			$this->display();
			return true;
		}
		return false;
	}

	function init()
	{
		global $config;

		$this->start = _read('start', TYPE_INT);
		$this->ppage = _read('ppage', TYPE_INT, intval($config->data['topics_per_page']));
		$this->read();
		return true;
	}

	// get pms for box from db
	function read()
	{
		global $db, $config, $forums;
		global $sort_fields, $order_fields;
		global $view_user;

		// play differently for home page
		if ($this->box_id == 0)
		{
			return $this->read_home();
		}

		$this->data = array();
		$this->total = 0;
		$this->now = time();

		// buid the where selection
		$fromuser = preg_replace('/\*/', '%', $this->fields['fromuser']->value);
		$fromuser = trim(str_replace('%', '', $fromuser)) == '' ? '' : $fromuser;

		$msgdays = $this->fields['msgdays']->value;

		$sql_where = array();

		switch ($this->box_type)
		{
			case PM_BOXES_OUT:
				$sql_where[] = 'pm.privmsgs_type = ' . PRIVMSGS_NEW_MAIL . '
					AND pm.privmsgs_from_userid = ' . $view_user->data['user_id'];
				break;
			case PM_BOXES_SENT:
				$sql_where[] = 'pm.privmsgs_type = ' . PRIVMSGS_SENT_MAIL . '
					AND pm.privmsgs_from_userid = ' . $view_user->data['user_id'];
				break;
			case PM_BOXES_IN:
			default:
				$sql_where[] = '( pm.privmsgs_type = ' . PRIVMSGS_READ_MAIL . '
						OR pm.privmsgs_type = ' . PRIVMSGS_UNREAD_MAIL . '
						OR pm.privmsgs_type = ' . PRIVMSGS_NEW_MAIL . ' )
					AND pm.privmsgs_to_userid = ' . $view_user->data['user_id'];
				break;
		}

		// search by sender
		if ( !empty($fromuser) )
		{
			// Look for matching user_id and add to query
			$sql = 'SELECT user_id
				FROM ' . USERS_TABLE . '
				WHERE username LIKE \'' . $fromuser . '\'';
			if ($result = $db->sql_query($sql, false, __LINE__, __FILE__, false))
			{
				$row = $db->sql_fetchrow($result);
				if  ($this->box_type == PM_BOXES_IN)
				{
					$sql_where[] = 'pm.privmsgs_from_userid = ' . intval($row['user_id']);
				}
				else
				{
					$sql_where[] = 'pm.privmsgs_to_userid = ' . intval($row['user_id']);
				}
				$db->sql_freeresult($result);
			}
			else
			{
				_warning('Pm_user_not_found');
			}
		}

		// search by message age
		if ( !empty($msgdays) )
		{
			$sql_where[] = 'pm.privmsgs_date > ' . ($this->now - (intval($msgdays) * 86400));
		}

		// get sort and order
		$sort_field = $sort_fields[ $this->fields['sort']->value ];
		$order_field = $order_fields[ $this->fields['order']->value ];

		// get all matching pms
		$privmsg_ids = array();
		$sql = 'SELECT pm.*, u.user_id, u.username, u2.user_id, u2.username
					FROM ' . PRIVMSGS_TABLE . ' pm, ' . USERS_TABLE . ' u, ' . USERS_TABLE . ' u2
					WHERE privmsgs_box = ' . $this->box_id . '
						AND pm.privmsgs_from_userid = u.user_id
						AND pm.privmsgs_to_userid = u2.user_id
						AND ' . implode('
						AND ', $sql_where) . '
					ORDER BY ' . $sort_field . $order_field . '
						LIMIT ' . $this->start . ', ' . $this->ppage;
		$result = $db->sql_query($sql, false, __LINE__, __FILE__);


		// organize the data into a data array and a map array
		$i = 0;
		while ( $row = $db->sql_fetchrow($result) )
		{
			$this->privmsg_ids[ intval($row['privmsgs_id']) ] = array('id' => $i, 'parent' => intval($row['privmsgs_original']));
			$this->data[$i] = $row;
			$i++;
		}
		$db->sql_freeresult($result);
	}

	function read_home()
	{


	}

	function check()
	{
	}

	function validate()
	{
		global $error, $error_msg, $dft_save_folder;
		global $config, $user, $db;
		global $attach_config;

		$pm = new advmsg_pm();
		$done = false;

		$this->select_box = array();
		$delete = _read('delete_details', TYPE_INT);
		$save = _read('save_details', TYPE_INT);

		// process save/delete
		if ( ($save || ( $delete && !_button('cancel_details') ) && !empty($this->data) )
		{
			$select_box = _read_array('select_box');
			$privmsgs_ids = _read_array('privmsgs_ids');
			$confirm = ($save) ? true : _button('confirm_details');
			$msg_ids = array();

			// check save details
			if ($save && ($this->box_type != PM_BOXES_OUT || $this->box_type != PM_BOXES_SAVE))
			{
				$save_to = _read('save_to', TYPE_INT, $this->boxes_map[$dft_save_folder]);
			}
			else
			{
				// trying to save something from outbox or savebox, so let's skip
				$save = false;
			}

			foreach ( $this->data as $idx => $data )
			{
				if ( isset($select_box[ ($idx + 1) ]) && (intval($this->data[$idx]['privmsgs_id']) == intval($privmsgs_ids[$idx])) )
				{
					if ( $confirm && intval($this->data[$idx]['privmsgs_id']) )
					{
						// got something to delete
						$msg_ids[] = intval($this->data[$idx]['privmsgs_id']);
					}
					else
					{
						// add for confirmation
						$this->select_box[ ($idx + 1) ] = true;
					}
				}
			}

			// save messages
			if ($save && $confirm && !empty($msg_ids))
			{
				$pm->save($msg_ids, $this->box_type, $save_to);
				$saved = true;
			}

			// delete messages
			if ($delete && $confirm && !empty($msg_ids))
			{
				$pm->delete($msg_ids, $this->box_type);
				$deleted = true;
			}

			// No save or deleting done, so likely an input error
			if (!save && !warning)
			{
				_warning('Pms_input_error');
			}
		}

		// send message
		if ( $deleted )
		{
			message_return('Pms_deleted', 'Click_return_pm_box', $config->url($this->requester, $this->parms, true));
		}

		if ( $saved )
		{
			message_return('Pms_saved', 'Click_return_pm_box', $config->url($this->requester, $this->parms, true));
		}
	}

	function get_link_parms()
	{
		global $dft_sort, $dft_order;

		$parms = $this->parms;
		if ( $this->fields['sort']->value != $dft_sort )
		{
			$parms['sort'] = $this->fields['sort']->value;
		}
		if ( $this->fields['order']->value != $dft_order )
		{
			$parms['order'] = $this->fields['order']->value;
		}

		if ( trim($this->fields['fromuser']->value) != '' )
		{
			$parms['fromuser'] = rawurlencode($this->fields['fromuser']->value);
		}

		if ( intval($this->fields['msgdays']->value) )
		{
			$parms['msgdays'] = intval($this->fields['msgdays']->value);
		}
		return $parms;
	}

	// get available save boxes
	function get_save_tos()
	{
		$array = array();
		foreach ($this->boxes as $box)
		{
			if ($box['pm_box_type'] == PM_BOXES_SAVE)
			{
				$array[$box['pm_box_id']] = $box['pm_box_txt'];
			}
		}
		return $array;
	}

	// display pm box
	function display()
	{

		global $template, $user, $config, $pm;
		global $view_user, $warning, $warning_msg;
		global $sort_fields, $order_fields;
		global $dft_sort, $dft_order, $dft_save_folder;

		if ($this->box_id == 0)
		{
			return $this->display_home();
		}

		// give warning
		if ( $warning )
		{
			$template->assign_block_vars('warning', array(
				'WARNING_TITLE' => $user->lang('Information'),
				'WARNING_MSG' => $warning_msg,
			));
		}
		// send delete confirm
		if ( _button('delete_details') && !empty($this->select_box) && !_button('cancel_details') && !_button('confirm_details') )
		{
			$template->assign_vars(array(
				'L_FORM' => $user->lang('Confirm'),
				'MESSAGE' => $user->lang('Confirm_delete_pms'),
			));
			display_buttons(array(
				'confirm_details' => array('txt' => 'Delete', 'img' => 'cmd_delete', 'key' => 'cmd_delete'),
				'cancel_details' => array('txt' => 'Cancel', 'img' => 'cmd_cancel', 'key' => 'cmd_cancel'),
			));
			$template->set_switch('form');
			$template->assign_vars(array('FORM' => $template->include_file('ucp/ucp_confirm_box.tpl')));

			// hide delete
			_hide('delete_details', true);

			// hide selection values
			if ( !empty($this->data) )
			{
				foreach ( $this->data as $idx => $data )
				{
					if ( isset($this->select_box[ ($idx + 1) ]) )
					{
						_hide('select_box[]', $idx + 1, true);
					}
					_hide('privmsgs_ids[]', $this->data[$idx]['privmsgs_id'], true);
				}
			}

			// hide search values
			foreach ( $this->fields as $field_name => $field )
			{
				_hide($field_name, $this->fields[$field_name]->form_escape_string($this->fields[$field_name]->value));
			}
			return;
		}

		// display search form
		foreach ( $this->fields as $field_name => $field )
		{
			$this->fields[$field_name]->display();
		}
		display_buttons($this->buttons);
		$template->assign_vars(array('SEARCH_FORM' => $template->include_file('form_fields.tpl', array('field'))));

		// display details
		if ( $count_data = count($this->data) )
		{
			$row_to_color = $row_from_color = false;
			for ( $i = 0; $i < $count_data; $i++ )
			{
				$row = $this->data[$i];
				$privmsgs_id = intval($row['privmsgs_id']);
				$flag = $row['privmsgs_type'];
				$icon_flag = ( $flag == PRIVMSGS_NEW_MAIL || $flag == PRIVMSGS_UNREAD_MAIL ) ? $user->img('pm_unreadmsg') : $user->img('pm_readmsg');
				$icon_flag_alt = ( $flag == PRIVMSGS_NEW_MAIL || $flag == PRIVMSGS_UNREAD_MAIL ) ? $user->lang('Unread_message') : $user->lang('Read_message');

				// Split the messages (for saveboxes) into to/from current user
				$row_type = (intval($row['privmsgs_from_userid']) == $view_user->data['user_id']) ? 'row_from' : 'row_to';
				$row_color = $row_type . '_color';
				$$row_color = !$$row_color;

				$template->assign_block_vars('row', array(
					'ROW_NUMBER' => $i + 1,
					'PRIVMSGS_ID' => intval($row['privmsgs_id']),
					'U_MESSAGE' => $config->url('usercp', array('mode'=>'privmsg', 'sub'=>'pm_read', POST_POST_URL => $row['privmsgs_id']), true),

					'FLAG' => $user->lang('Flag'),
					'SUBJECT' => $user->lang('Subject'),
					'DATE' => $user->lang('Date'),
					'FROM' => $user->lang('From'),
					'MARK_ALL' => $user->lang('Mark_all'),
				));
				$template->set_switch($row_type . '.light', $$row_color);
			}
		}

		// display header
		if ($user->auth(POST_GROUP_URL, 'ucp_pm_new', GROUP_REGISTERED))
		{
			$post_pm = $config->url('usercp', array('mode'=>'privmsg', 'sub'=>'pm_post', 'mode'=>'post'), true);
			$post_pm_img = '<a href="' . $post_pm . '"><img src="' . $user->img('pm_postmsg') . '" alt="' . $user->lang('Post_new_pm') . '" border="0" /></a>';
			$post_new_mesg_url = '<a href="' . $post_pm . '"><img src="' . $user->img('post_new') . '" alt="' . $user->lang('Send_a_new_message') . '" border="0" /></a>';
			$post_pm = '<a href="' . $post_pm . '">' . $user->lang('Post_new_pm') . '</a>';
		}
		else
		{
			$post_pm = '';
			$post_pm_img = '';
		}

		$template->assign_vars(array(
			'BOX_NAME' => $this->boxes[$this->box_id]['pm_box_txt'],
			'BOX_IMG' => $this->boxes[$this->box_id]['pm_box_img'],

			'POST_PM_IMG' => $post_pm_img,
			'POST_PM' => $post_pm,

			'L_MARK' => $user->lang('Mark'),
			'L_FLAG' => $user->lang('Flag'),
			'L_SUBJECT' => $user->lang('Subject'),
			'L_DATE' => $user->lang('Date'),
			'L_DISPLAY_MESSAGES' => $user->lang('Display_messages'),
			'L_FROM' => $user->lang('From'),
			'L_TO' => $user->lang('To'),
			'L_MARK_ALL' => $user->lang('Mark_all'),
			'L_UNMARK_ALL' => $user->lang('Unmark_all'),
			'L_DELETE_MARKED' => $user->lang('Delete_marked'),
			'L_DELETE_ALL' => $user->lang('Delete_all'),
			'L_SAVE_MARKED' => $user->lang('Save_marked'),

			'S_PRIVMSGS_ACTION' => $config->url('usercp', array('mode'=>'privmsg', 'sub'=>'pm_box', 'folder'=>$this->box), true),
		));

		$template->set_switch('details');
		$details_buttons = array(
			'delete_details' => array('txt' => 'Delete_marked', 'img' => 'cmd_delete', 'key' => 'cmd_delete'),
			'save_details' => array('txt' => 'Save_marked', 'img' => 'cmd_save', 'key' => 'cmd_save'),
		);
		display_buttons($details_buttons, 'details');

		$parms = $this->get_link_parms();
		$pagination = new pagination($this->requester, $parms);
		$pagination->display('pagination', $this->total, $this->ppage, $this->start, true, 'Attachments_count');
		unset($pagination);

		// send all to template
		$template->assign_block_vars('cp_content', array('BOX' => $template->include_file('ucp/ucp_advmsg_pm_box.tpl')));

		// quota box
		$this->display_quota();

		// attachment quota box
		if ( $config->data['mod_attachment_CH'] )
		{
			$this->display_attach_quota();
		}
	}

	// @private display pm box quota
	function display_quota()
	{
		global $template, $db, $view_user, $user, $config;
		global $cp_no_menus, $cp_menu_title, $cp_requester, $cp_parms, $cp_panels, $menus, $sub_menus, $ctx_menus, $menu_id, $subm_id, $ctx_id;

		// we handle the menu to display it first
		$cp_no_menus = true;
		$template->assign_vars(array(
			'L_MENU' => $cp_menu_title,
		));
		$cp_panels->display_menus($menus, $sub_menus, $ctx_menus, $menu_id, $subm_id, $ctx_id, $cp_requester, $cp_parms);

		// get quota size
		$box_limit_value = intval($this->boxes[$this->box_id]['pm_box_limit']);
		if ( $box_limit_value == 0 )
		{
			$box_limit = $user->lang('Unlimited');
		}
		else
		{
			$box_limit = round($box_limit_value / max(1, limit), 2) . ' ' . $user->lang('private_messages');
		}

		// get pm count
		$sql = 'SELECT COUNT(pm.privmsgs_id) AS sum
					FROM ' . PRIVMSGS_TABLE . ' pm
					WHERE pm.privmsgs_box = ' . $this->box_id;
		switch ($this->box_type)
		{
			case PM_BOXES_IN:
				$sql .= '( pm.privmsgs_type = ' . PRIVMSGS_READ_MAIL . '
						OR pm.privmsgs_type = ' . PRIVMSGS_UNREAD_MAIL . '
						OR pm.privmsgs_type = ' . PRIVMSGS_NEW_MAIL . ' )
					AND pm.privmsgs_to_userid = ' . $view_user->data['user_id'];
				break;
			case PM_BOXES_OUT:
				$sql .= 'pm.privmsgs_type = ' . PRIVMSGS_NEW_MAIL . '
					AND pm.privmsgs_from_userid = ' . $view_user->data['user_id'];
				break;
			case PM_BOXES_SENT:
				$sql .= 'pm.privmsgs_type = ' . PRIVMSGS_SENT_MAIL . '
					AND pm.privmsgs_from_userid = ' . $view_user->data['user_id'];
				break;
			case PM_BOXES_SAVE:
			default:
				$sql .= '( ( pm.privmsgs_type = ' . PRIVMSGS_SAVED_OUT_MAIL . '
						AND  pm.privmsgs_from_userid = ' . $view_user->data['user_id'] . ' )
					OR ( pm.privmsgs_type = ' . PRIVMSGS_SAVED_IN_MAIL . '
						AND pm.privmsgs_to_userid = ' . $view_user->data['user_id'] . ' ) )';
				break;
		}
		$result = $db->sql_query($sql, false, __LINE__, __FILE__);
		$box_pm_value = ($row = $db->sql_fetchrow($result)) ? intval($row['sum']) : 0;
		$db->sql_freeresult($result);

		$box_pm = round($box_pm_value / max(1, $box_pm_value), 2) . ' ' . $user->lang('private_messages');

		// then we display the quota block
		$template->assign_block_vars('pm_box_quota', array(
			'L_QUOTA' => sprintf($user->lang('Pm_quota_profile'), $box_limit),
			'L_BOX_QUOTA' => sprintf($user->lang('pm_box_quota'), $this->box, $box_pm),
			'QUOTA_BOX' => get_quota_box('Pm_percent_profile', $box_pm_value, $box_limit_value),
		));
		$template->assign_block_vars('cp_menus', array('BOX' => $template->include_file('ucp/ucp_advmsg_quota_box.tpl', array('pm_box_quota'))));
	}

	// @private display pm attachments quota box
	function display_attach_quota()
	{
		global $template, $db, $user, $config;
		global $attach_config, $attachment;
		global $view_user;
		global $cp_no_menus, $cp_menu_title, $cp_requester, $cp_parms, $cp_panels, $menus, $sub_menus, $ctx_menus, $menu_id, $subm_id, $ctx_id;

		// we handle the menu to display it first
		$cp_no_menus = true;
		$template->assign_vars(array(
			'L_MENU' => $cp_menu_title,
		));
		$cp_panels->display_menus($menus, $sub_menus, $ctx_menus, $menu_id, $subm_id, $ctx_id, $cp_requester, $cp_parms);

		// get quota size
		$attachment->get_quota_limits($user->data, PAGE_PRIVMSGS);
		$filesize_limit_value = intval($attach_config->data['upload_filesize_limit']) ? intval($attach_config->data['upload_filesize_limit']) : intval($attach_config->data['attachment_quota']);
		if ( empty($filesize_limit_value) )
		{
			$filesize_limit_unit = '';
			$filesize_limit = $user->lang('Unlimited');
		}
		else
		{
			$units = array();
			$filesize_limit_unit = size_get_units($filesize_limit_value, $units);
			$filesize_limit = round($filesize_limit_value / max(1, $filesize_limit_unit), 2) . ' ' . $user->lang($units[$filesize_limit_unit]);
		}

		// get upload size (only posts)
		$from_user = array(PRIVMSGS_SENT_MAIL, PRIVMSGS_NEW_MAIL, PRIVMSGS_SAVED_OUT_MAIL);
		$to_user = array(PRIVMSGS_READ_MAIL, PRIVMSGS_NEW_MAIL, PRIVMSGS_UNREAD_MAIL, PRIVMSGS_SAVED_IN_MAIL);
		$sql = 'SELECT SUM(d.filesize) AS sum_filesize
					FROM ' . ATT_DESC_TABLE . ' d, ' . ATT_LINKS_TABLE . ' a, ' . PRIVMSGS_TABLE . ' p
					WHERE d.attach_id = a.attach_id
						AND p.privmsgs_id = a.privmsgs_id
						AND a.post_id = 0
						AND ((p.privmsgs_from_userid = ' . intval($view_user->data['user_id']) . ' AND p.privmsgs_type IN(' . implode(', ', $from_user) . '))
							OR (p.privmsgs_to_userid = ' . intval($view_user->data['user_id']) . ' AND p.privmsgs_type IN(' . implode(', ', $to_user) . ')))';
		$result = $db->sql_query($sql, false, __LINE__, __FILE__);
		$filesize_upload_value = ($row = $db->sql_fetchrow($result)) ? intval($row['sum_filesize']) : 0;
		$db->sql_freeresult($result);

		$units = array();
		$filesize_upload_unit = size_get_units($filesize_upload_value, $units);
		$filesize_upload = round($filesize_upload_value / max(1, $filesize_upload_unit), 2) . ' ' . $user->lang($units[$filesize_upload_unit]);

		// then we display the quota block
		$template->assign_block_vars('attach_quota', array(
			'L_QUOTA' => sprintf($user->lang('User_quota_profile'), $filesize_limit),
			'L_UPLOADED' => sprintf($user->lang('User_uploaded_profile'), $filesize_upload),
			'QUOTA_BOX' => get_quota_box('Upload_percent_profile', $filesize_upload_value, $filesize_limit_value),
		));
		$template->assign_block_vars('cp_menus', array('BOX' => $template->include_file('ucp/ucp_attach_quota_box.tpl', array('attach_quota'))));
	}
}

// process
$parms = array(
	'mode' => $menu_id,
	'sub' => $subm_id == $menu_id ? '' : $subm_id,
	'ctx' => $ctx_id == $subm_id ? '' : $ctx_id,
);
$form = new pm_box($cp_requester, $cp_parms + $parms, $fields);
$form->process();
$template->set_filenames(array('body' => 'cp_generic.tpl'));

?>